package com.liujun.spring4.demo.aop.iocset.xmlset.factoryBean;

import org.springframework.beans.factory.FactoryBean;

/**
 * @author liujun
 * @version 1.0
 * @date 2018-08-18 10:37:00
 */
public class CarFactoryBean implements FactoryBean<Car> {

    private String carInfo;

    public String getCarInfo() {
        return carInfo;
    }

    public void setCarInfo(String carInfo) {
        this.carInfo = carInfo;
    }

    @Override
    public Car getObject() throws Exception {

        Car car = new Car();

        String[] carArray = carInfo.split(",");
        car.setBrand(carArray[0]);
        car.setMaxSpeed(Integer.parseInt(carArray[1]));
        car.setPrice(Double.parseDouble(carArray[2]));

        return car;
    }

    @Override
    public Class<?> getObjectType() {
        return Car.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}
